<?php
namespace Amis;
function dump($res)
{
    echo "<pre>";
    var_dump($res);
    echo "</pre>";
}
require_once 'vendor/autoload.php';

use Amis\facade\layout\Page;
use Amis\facade\form\InputText;
use Amis\facade\dataviewer\CRUD;
use Amis\facade\functions\ActionType;
use Amis\facade\dataviewer\CrudFilter;
use Amis\facade\dataviewer\TableColumns;

header('Content-type:application/json');
$json = Page::title('数据列表')
    ->toolbar([
        ActionType::actionType('link')->label('新增'),
    ])
    ->body([
        CRUD::title('用户数据表')
            ->api('https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample')
            ->filter(
                CrudFilter::title('搜索')->body(
                    InputText::name('keywords')->label('关键字搜索'),
                )
            )
            ->bulkActions([
                [
                    "label"      => "批量修改",
                    "type"       => "button",
                    "actionType" => "dialog",
                    "level"      => "primary",
                    "dialog"     => [
                        "title" => "批量编辑",
                        "name"  => "sample-bulk-edit",
                        "body"  => [
                            "type"     => "form",
                            "api"      => "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/bulkUpdate2",
                            "controls" => [
                                [
                                    "type"  => "text",
                                    "name"  => "engine",
                                    "label" => "Engine",
                                ],
                            ],
                        ],
                    ],
                ],
                [
                    "label"       => "批量删除",
                    "type"        => "button",
                    "level"       => "danger",
                    "actionType"  => "ajax",
                    "api"         => "delete:https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/\$ids",
                    "confirmText" => "确定要批量删除?",
                ],
            ])
            ->columns(TableColumns::name('id')->label('ID')->width('20')->sortable(true))
        ,
    ]);
echo json_encode($json);
die;